<?php
namespace app\api\model;


use app\api\model\Topic;
use app\common\model\Users as UsersModel;
use app\api\model\Dynamic;
use app\api\model\Banner;
class Users extends UsersModel
{
    /**
     * 关联会员组表
     *
     */
    public function users_group()
    {
        return $this->hasOne('Users_group','users_group_id','id');
    }
    /**
     * 关联婚姻状况表
     *
     */
    public function marriage()
    {
        return $this->hasOne('Marriage','id','marriage_id');
    }

    /**
     * 关联单位性质表
     */
    public function nature()
    {
        return $this->hasOne('Nature','id','nature_id');
    }
    /**
     * 关联年薪表
     */
    public function salary()
    {
        return $this->hasOne('Salary','id','salary_id');
    }
    /**
     * 关联住房信息表
     */
    public function house()
    {
        return $this->hasOne('House','id','house_id');
    }
    /**
     * 关联属相表
     */
    public function zodiac()
    {
        return $this->hasOne('Zodiac','id','zodiac_id');
    }
    /**
     * 关联星座表
     */
    public function constellation()
    {
        return $this->hasOne('Constellation','id','constellation_id');
    }
    /**
     * 关联性格表
     */
    public function character()
    {
        return $this->hasMany('Character','id','character_ids');
    }

    /**
     * 关联爱好表
     */
    public function hobby()
    {
        return $this->hasMany('Hobby','id','hobby_ids');
    }
    /**
     * 关联户籍表
     */
    public function household()
    {
        return $this->hasOne('Household', 'id', 'household_id');

    }
    /**
     * 关联现居地表
     */
        public function current()
    {
        return $this->hasOne('Current','id','current_id');
    }
    /**
     * 关联现居地表
     */
    public function education()
    {
        return $this->hasOne('Education','id','education_id');
    }
    /**
     * 关联岗位性质表
     */
    public function post()
    {
        return $this->hasOne('Post','id','post_id');
    }
    /**
     * 关联所属行业表
     */
    public function industry()
    {
        return $this->hasOne('Industry','id','industry_id');
    }
    /**
     * 关联购车管理表
     */
    public function car()
    {
        return $this->hasOne('Car','id','car_id');
    }
    /**
     * 关联红娘表
     *
     */
    public function matchmaker()
    {
        return $this->hasOne('Matchmaker','id','matchmaker_id');
    }
    /**
//    /**
//     * 关联爱好表
//     */
//    public function hobby()
//    {
//        return $this->hasMany('Hobby','id','hobby_ids');
//    }

    /**
    * 获取用户列表
    *
    */
   public function userlist($uid)
   {
       $userinfos = UsersModel::with('usersgroup')->where('id',$uid)->find();
       $userinfo = json_encode($userinfos);
       //获取登录用户性别  如果为男 只推荐女    反之  只推荐男
       if($userinfo['genderdata'] == 'male')
       {
          $userlist = UsersModel::where('genderdata','=','female')->order('group_id desc')->select();
       }else{
           $userlist = UsersModel::where('genderdata','=','male')->order('group_id desc')->select();
       }
       return json($userlist);
   }

   /**
    * 会员详情
    *
    */
   public function userdetail($uid)
   {
       var_dump(111);
       //关联形象图片表获取形象照  关联标签表 关联评论表 评论表关联话题表获取数据
      $detail =  $this->with('marriage,nature,salary,house,zodiac,constellation,character,hobby,household,current,education,post,industry,car')->where('id',$uid)->find()->toArray();
      var_dump($detail['marriage']['name']);
      return $detail;
   //根据当前登录用户的实名情况判断显示内容  yes已实名  no未实名

      if($userinfo['real'] == 'yes'){
          //如果当前登录的用户已经实名获取到页面所有的数据
         return $detail;
      }
      //没有获取到当前登录用户信息 只显示三条
      if(!isset($userinfo)){
          //评论表关联话题表 没有查到登录用户信息只显示3条话题
        $topic = Comment::with('topic')->where('user_id',$uid)->limit(3)->select();
        //将上面查到的$detail与$topic组合在一起返回

      }else{
          $topic = Comment::with('topic')->where('user_id',$uid)->select();
      }
            //个人动态
      $ports =  Dynamic::where('user_id',$uid)->select();

   }


}